import { createRouter, createWebHistory } from 'vue-router'
import Home from '@/views/Home.vue' // 首页
// const NotFound = () => import("@/views/404/index.vue");


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    // 添加通配符路由，匹配404
    {
      path: '/:pathMatch(.*)*',
      name: 'NotFound',
      // component: NotFound,
      component: () => {
        window.location.href = '/404.html'
        return new Promise(() => { })
      }
    }
  ]
})

router.beforeEach((to, from, next) => {
  // 如果即将进入的路由没有定义 `meta.footer`，则默认设置为 `true`
  if (to.meta.footer === undefined)
    to.meta.footer = true

  next()
})

export default router
